<!DOCTYPE html>
<html lang="en">

<head>
    <!-- 设置字符编码为 UTF-8 -->
    <meta charset="UTF-8">
    <!-- 设置视口，使页面在不同设备上正确显示 -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入 Tailwind CSS 库 -->
    <script src="https://unpkg.com/@tailwindcss/browser@4"></script>
    <!-- 引入 Font Awesome 图标库 -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <!-- 设置页面标题 -->
    <title>登录界面</title>
</head>

<body class="bg-gray-100 flex justify-center items-center h-screen">
    <!-- 登录表单容器，设置背景色、内边距、圆角和阴影 -->
    <div class="bg-white p-8 rounded-lg shadow-md w-full max-w-md">
        <!-- 登录标题 -->
        <h2 class="text-2xl font-bold text-center mb-6">登录</h2>
        <!-- 登录表单，设置 id 为 loginForm -->
        <form id="loginForm">
            <!-- 用户名输入框容器 -->
            <div class="mb-4">
                <!-- 用户名标签 -->
                <label for="username" class="block text-gray-700 font-bold mb-2">用户名</label>
                <!-- 用户名输入框，设置样式和占位符 -->
                <input type="text" id="username" class="border border-gray-300 p-2 w-full rounded focus:outline-none focus:border-blue-500" placeholder="请输入用户名">
            </div>
            <!-- 密码输入框容器 -->
            <div class="mb-6">
                <!-- 密码标签 -->
                <label for="password" class="block text-gray-700 font-bold mb-2">密码</label>
                <!-- 密码输入框，设置样式和占位符 -->
                <input type="password" id="password" class="border border-gray-300 p-2 w-full rounded focus:outline-none focus:border-blue-500" placeholder="请输入密码">
            </div>
            <!-- 登录按钮，设置样式和交互效果 -->
            <button type="submit" class="bg-blue-500 text-white py-2 px-4 rounded w-full hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:ring-opacity-50 transition duration-300 ease-in-out">登录</button>
        </form>
        <!-- 消息提示容器，初始设置为红色文字 -->
        <div id="message" class="text-center mt-4 text-red-500"></div>
    </div>

    <script>
        // 获取登录表单元素
        const loginForm = document.getElementById('loginForm');
        // 获取消息提示元素
        const message = document.getElementById('message');

        // 为表单添加提交事件监听器
        loginForm.addEventListener('submit', function (e) {
            // 阻止表单默认提交行为
            e.preventDefault();
            // 获取输入的用户名
            const username = document.getElementById('username').value;
            // 获取输入的密码
            const password = document.getElementById('password').value;

            // 验证用户名和密码
            if (username === 'admin' && password === 'password') {
                // 登录成功，显示成功消息并设置文字颜色为绿色
                message.textContent = '登录成功！';
                message.classList.remove('text-red-500');
                message.classList.add('text-green-500');
            } else {
                // 登录失败，显示错误消息并设置文字颜色为红色
                message.textContent = '用户名或密码错误，请重试。';
                message.classList.remove('text-green-500');
                message.classList.add('text-red-500');
            }
        });
    </script>
</body>

</html>
    